<html>
	<head>
		<title>GAMER.ru Ext 0.3.7</title>
		<script type="text/javascript" src="/js/jquery.js"></script>
		<script type="text/javascript">
		//
		// Класс настроек
		//
		Options = {
		
			ext_winter_mode: false,
			ext_select_own_comments: true,
			ext_lighting_links: true,
			ext_hide_counters: false,
			ext_hide_top_companies: false,
			ext_cloud_up: false,
			ext_hide_sidebar: false,
			ext_blacklist_users: new Array(),
			ext_whitelist_users: new Array(),
			ext_blacklist_blogs: new Array(),
			ext_tape_key: '',
			ext_tape_last: '',
			
			Save: function()
			{
				localStorage['ext_winter_mode'] = this.ext_winter_mode;
				localStorage['ext_select_own_comments'] = this.ext_select_own_comments;
				localStorage['ext_lighting_links'] = this.ext_lighting_links;
				localStorage['ext_hide_counters'] = this.ext_hide_counters;
				localStorage['ext_hide_top_companies'] = this.ext_hide_top_companies;
				localStorage['ext_cloud_up'] = this.ext_cloud_up;
				localStorage['ext_hide_sidebar'] = this.ext_hide_sidebar;

				localStorage['ext_blacklist_users'] = this.ext_blacklist_users.join('|');
				localStorage['ext_whitelist_users'] = this.ext_whitelist_users.join('|');
				localStorage['ext_blacklist_blogs'] = this.ext_blacklist_blogs.join('|');
			},
			
			Load: function()
			{
				this.ext_winter_mode = localStorage['ext_winter_mode'] == 'true';
				this.ext_select_own_comments = localStorage['ext_select_own_comments'] == 'true';
				this.ext_lighting_links = localStorage['ext_lighting_links'] == 'true';
				this.ext_hide_counters = localStorage['ext_hide_counters'] == 'true';
				this.ext_hide_top_companies = localStorage['ext_hide_top_companies'] == 'true';
				this.ext_cloud_up = localStorage['ext_cloud_up'] == 'true';
				this.ext_hide_sidebar = localStorage['ext_hide_sidebar'] == 'true';
				
				this.ext_blacklist_users = localStorage['ext_blacklist_users'].split('|');
				this.ext_whitelist_users = localStorage['ext_whitelist_users'].split('|');
				this.ext_blacklist_blogs = localStorage['ext_blacklist_blogs'].split('|');
			}
		}
		
		//
		// Загрузка настроек
		//
		Options.Load();
		
		//
		// Отдаем значение настроек по запросу
		//
		chrome.extension.onRequest.addListener(function(request, sender, sendResponse) 
		{
			var v = eval('Options.' + request);
			sendResponse(v);
		});
		
		//
		// Функция проверки ленты пользователя
		//
		function refresh_lenta()
		{
			$.get('http://www.gamer.ru/', null, function(data, status)
			{
				if($('a.my_proff', data).text() != 'Профиль')
				{
					chrome.browserAction.setBadgeBackgroundColor({color: [174, 174, 174, 255]});
					chrome.browserAction.setBadgeText({text: '?'});
					return;
				}
				else
				{				
					if($('#item_lenta div', data).context == 'undefined') return;
					var count = parseInt($('#item_lenta div', data).text().replace('+', ''));
					if(count > 0)
					{
						console.log('new ' + count + ' posts');
						chrome.browserAction.setBadgeBackgroundColor({color: [200, 0, 0, 255]});
						chrome.browserAction.setBadgeText({text: '' + count});					
					}
					else
					{
						chrome.browserAction.setBadgeText({text:''});	
					}
				}
			});
		}
		
		//
		// Раз в минуту проверяем ленту
		//
		refresh_lenta();
		setInterval('refresh_lenta()', 60000);
		
		//
		// Открываем ленту при нажатии
		//
		chrome.browserAction.onClicked.addListener(function(tab)
		{
			chrome.tabs.create({url: 'http://gamer.ru/lenta', selected: true}, function(){});
		});
		</script>
	</head>
	<body></body>
</html>